import { ClassicModel } from "../../models/classic";
import { LikeModel } from "../../models/like";
import { ClassicLatestProp } from "../../props/classic";

const classicModel = new ClassicModel()
const likeModel = new LikeModel()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    classic: {},
    first: false,
    latest: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("onLoad=>", options)
    // 数据更新
    classicModel.getLatest((res) => {
      this.setData({
        classic: res
      })
    });
  },
  /**
   * 点赞、取消点赞--事件
   * @param event 
   */
  handleLike(event: WechatMiniprogram.TouchEvent) {
    let behavior = event.detail.behavior;
    let classic = this.data.classic as ClassicLatestProp
    likeModel.like(behavior, classic.id, classic.type)
  },
  /**
  * 监听左箭头点击事件
  */
  handleNext(event: WechatMiniprogram.TouchEvent) {
    console.log("handleNext=>Click", event)
  },
  /**
  * 监听右箭头点击事件
  */
  handlePrevious(event: WechatMiniprogram.TouchEvent) {
    console.log("handlePrevious=>Click", event)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})